package com.lujieni.springbootjvm.classloader;

/**
 * 类初始化时机(即执行static{}的时机)
 */
public class LazyLoading {

    public static void main(String[] args) throws ClassNotFoundException {
        //Son son = new Son(); // 会初始化
        System.out.println(Parent.i); // final+static+基本类型 不会初始化该类,如果是引用类型类就会加载
        //System.out.println(Parent.j); // static+基本类型类会初始化该类
        //Class<?> clazz = Class.forName("com.lujieni.springbootjvm.classloader.LazyLoading$Parent"); // 反射会初始化目标类
    }

    private static class Parent{

        private final static int i = 20;

        private static int j = 100;

        static {
            System.out.println("Parent");
        }
    }

    private static class Son extends Parent{

        static {
            System.out.println("Son");
        }
    }

}
